from core.ocr_facade import MhxyQAOcrFacade
from core.log import logger
maocr = MhxyQAOcrFacade()

def test_signup(u, e, p, i):
    maocr.signup(u, e, p, i)
    
def test_recognize(id, file_img):
    text, res, ok = maocr.recognize(id, file_img)
    # delete_file(file_img)
    if ok:
        logger.info(text)
        logger.info(res)
    else:
        logger.info(f"ocr failed!{file_img}")

def test_coord_ocr(file_img, token):
    coord, ok = maocr.mhxy_coord_ocr(file_img, token)
    print(coord)
    
if __name__ == '__main__':
    # file_img = r"images/shot/q5.png"
    # id = 53
    # test_recognize(id, file_img)
    
    # u = "admin"
    # p = "123"
    # e = "admin@mhxyqa.com"
    # i = "abc"
    # test_signup(u, e, p, i)
    
    from core.util import loadini_user, loadini_setting
    import core.model_signin as u
    import setting as c
    
    res, ok = loadini_setting()
    if ok:
        c.URL_QA = f"http://{res[0]}:{res[1]}"
        logger.info(c.URL_QA)
        logger.info(c.URL_QA_OCR())
    
    
    s, u.signin_flag = loadini_user()
    if u.signin_flag:
        logger.info(f"load user: {s}")
        u.signin_username = s[0]
        u.signin_email = s[1]
        u.signin_token = s[2]
        u.signin_invatation = s[3]    
        test_coord_ocr("D:\workspace\mhxyQA_GUI\images\shot\\1712761099.png", u.signin_token )
    
    